package com.tl.architecture.base.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

/**
 * databinding fragment
 */
abstract class BaseVDBFragment<VDB : ViewDataBinding> : BaseFragment() {

    protected var dataBinding: VDB? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        dataBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false)
        dataBinding?.lifecycleOwner = this//将设置数据的生命周期与fragment绑定
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    abstract fun getLayoutId(): Int

    override fun onDestroyView() {
        super.onDestroyView()
        dataBinding = null//防止内存泄露
    }
}